<?php
	include "LogPoint_implementation.php";
	include "GetPointString_implementation.php";
	
	echo "<p>Jam Dodge Backend Testing:</p>";
	
	connectToSQL();
	correct_single_point();
	database_clean();
	no_single_point();
	database_clean();
	correct_multiple_point();
	database_clean();
	no_multiple_point();
	database_clean();
	correct_averaging();
	database_clean();
	closeConnection();
	
	function database_clean()
	{
		global $databaseName, $connection, $point;	
		mysql_select_db($databaseName, $connection);
		
		$sqlStringDeletePoint = "DELETE FROM points WHERE Latitude BETWEEN 0 AND 2 AND Longitude BETWEEN 0 AND 2 AND Bearing BETWEEN 0 AND 360";
		mysql_query($sqlStringDeletePoint);
	}
	
	function correct_single_point()
	{
		LogPoint( 1, 1, 1, 1 );
		$string = populatePointArrays(0, 2, 2, 0);
		$string = substr($string,0,-1); 
		
		$stringExpected = "1.00000 1.00000 1.00000 FF0000 1";
		
		if ( strcasecmp ( $string, $stringExpected ) == 0 )
			echo "<p>correct_single_point:</p> <p>Test Passed!</p>";
		else
			echo "<p>correct_single_point:</p> <p>Test Failed!</p> </p>Expected:".$stringExpected." Actual:".$string."</p>";
	}
	
	function no_single_point()
	{
		LogPoint( 1, 1, 1, 1 );
		$string = populatePointArrays(0, -1, -1, 0); //region with no point
		$string = substr($string,0,-1); 
		
		$stringExpected = "";
		
		if ( strcasecmp ( $string, $stringExpected ) == 0 )
			echo "<p>no_single_point:</p> <p>Test Passed!</p>";
		else
			echo "<p>no_single_point:</p> <p>Test Failed!</p> </p>Expected:".$stringExpected." Actual:".$string."</p>";
	}
	
	function correct_multiple_point()
	{
		LogPoint( 1, 1, 1, 1 );
		LogPoint( 1.2, 1.2, 1, 180);
		LogPoint( 0.8, 0.8, 2, 0 );
		$string = populatePointArrays(0, 3, 3, 0);
		$string = substr($string,0,-1);
		
		$stringExpected = "0.80000 0.80000 0.00000 FF0000 2;1.20000 1.20000 180.00000 FF0000 1;1.00000 1.00000 1.00000 FF0000 1";
		
		if ( strcasecmp ( $string, $stringExpected ) == 0 )
			echo "<p>correct_multiple_point:</p> <p>Test Passed!</p>";
		else
			echo "<p>correct_multiple_point:</p> <p>Test Failed!</p> </p>Expected:".$stringExpected." Actual:".$string."</p>";
	}
	
	function no_multiple_point()
	{
		LogPoint( 1, 1, 1, 1 );
		LogPoint( 1.2, 1.2, 1, 180);
		LogPoint( 0.8, 0.8, 2, 0 );
		$string = populatePointArrays(0, -1, -1, 0); //region with no points
		$string = substr($string,0,-1); 
		
		$stringExpected = "";
		
		if ( strcasecmp ( $string, $stringExpected ) == 0 )
			echo "<p>no_multiple_point:</p> <p>Test Passed!</p>";
		else
			echo "<p>no_multiple_point:</p> <p>Test Failed!</p> </p>Expected:".$stringExpected." Actual:".$string."</p>";
	}
	
	function correct_averaging()
	{
		LogPoint( 1, 1, 1, 0 );
		LogPoint( 1.0001, 1.0001, 3, 90);
		$string = populatePointArrays(0, 3, 3, 0);
		$string = substr($string,0,-1); 
		
		$stringExpected = "1.00010 1.00010 45.00000 FF0000 2";
		
		if ( strcasecmp ( $string, $stringExpected ) == 0 )
			echo "<p>correct_averaging:</p> <p>Test Passed!</p>";
		else
			echo "<p>correct_averaging:</p> <p>Test Failed!</p> </p>Expected:".$stringExpected." Actual:".$string."</p>";
	}
	
	
?>